package com.macro.mall.controller;


import com.macro.mall.common.api.CommonResult;
import com.macro.mall.entity.GuidancePrice;
import com.macro.mall.service.GuidancePriceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;


@RestController
@RequestMapping("/guidance")
@Api(tags = "GuidancePriceController", description = "指导价")
public class GuidancePriceController {

    @Autowired
    private GuidancePriceService guidancePriceService;

    @ApiOperation("查询记录")
    @RequestMapping(value = "/selectList", method = RequestMethod.POST)
    public CommonResult selectList(String project, Integer page, Integer size) {
        List<GuidancePrice> guidancePriceList = null;
        try {
            guidancePriceList = guidancePriceService.find(project, page, size);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed("服务器异常");
        }
        return CommonResult.success(guidancePriceList);
    }

    @ApiOperation("删除指导价")
    @RequestMapping(value = "/delOne", method = RequestMethod.POST)
    public CommonResult delOne(Integer id) {
        try {
            guidancePriceService.deleteById(id);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed("服务器异常");
        }
        return CommonResult.success("删除成功");
    }

    @ApiOperation("添加指导价")
    @RequestMapping(value = "/addOne", method = RequestMethod.POST)
    public CommonResult addOne(@RequestBody GuidancePrice guidancePrice) {
        try {
            guidancePriceService.saveNotNull(guidancePrice);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed("服务器异常");
        }
        return CommonResult.success("添加成功");
    }

    @ApiOperation("修改指导价")
    @RequestMapping(value = "/upDataOne", method = RequestMethod.POST)
    public CommonResult upDataOne(@RequestBody GuidancePrice guidancePrice) {
        try {
            guidancePriceService.updateNotNullById(guidancePrice);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed("服务器异常");
        }
        return CommonResult.success("修改成功");
    }
//    @ApiOperation("导入")
//    @RequestMapping(value = "/import", method = RequestMethod.POST)
//    public CommonResult imports(@RequestParam MultipartFile file) throws IOException {
//       return     guidancePriceService.imports(file);
//    }
}
